package com.two.shopping.service.serviceImpl;

import com.two.shopping.anno.Log;
import com.two.shopping.mapper.IAppraiseMapper;
import com.two.shopping.mapper.IOrderMapper;
import com.two.shopping.pojo.Orders;
import com.two.shopping.pojo.User;
import com.two.shopping.service.IAppraiseService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;

@Slf4j
@Service
public class AppraiseServiceImpl implements IAppraiseService {
    @Autowired
    private IAppraiseMapper appraiseMapper;
    @Autowired
    private IOrderMapper orderMapper;


    //评论商品
    @Override
    //开启事务
    @Transactional(rollbackFor = Exception.class)
    public void appraiseCommodity(Orders orders) {
        Orders orders1 = orderMapper.SelectIdOrders(orders);
        orders.setCommodityId(orders1.getCommodityId());
        orders.setUserId(orders1.getUserId());
        //评价商品
        orders.setUpdateTime(LocalDateTime.now());
        appraiseMapper.ordersCommodity(orders);
        //把订单状态设置为4，即已完成并评论
        orders.setState(4);
        log.info("此时orders值为{}", orders);
        orderMapper.Orders4(orders);
        log.info("此时orders值为{}", orders);
    }
}
